package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Fitnesslogs;
import com.ruoyi.system.service.IFitnesslogsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 健身日志Controller
 * 
 * @author 张英旺
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/system/fitnesslogs")
public class FitnesslogsController extends BaseController
{
    @Autowired
    private IFitnesslogsService fitnesslogsService;

    /**
     * 查询健身日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:fitnesslogs:list')")
    @GetMapping("/list")
    public TableDataInfo list(Fitnesslogs fitnesslogs)
    {
        startPage();
        List<Fitnesslogs> list = fitnesslogsService.selectFitnesslogsList(fitnesslogs);
        return getDataTable(list);
    }

    /**
     * 导出健身日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:fitnesslogs:export')")
    @Log(title = "健身日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Fitnesslogs fitnesslogs)
    {
        List<Fitnesslogs> list = fitnesslogsService.selectFitnesslogsList(fitnesslogs);
        ExcelUtil<Fitnesslogs> util = new ExcelUtil<Fitnesslogs>(Fitnesslogs.class);
        util.exportExcel(response, list, "健身日志数据");
    }

    /**
     * 获取健身日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fitnesslogs:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return success(fitnesslogsService.selectFitnesslogsByLogId(logId));
    }

    /**
     * 新增健身日志
     */
    @PreAuthorize("@ss.hasPermi('system:fitnesslogs:add')")
    @Log(title = "健身日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Fitnesslogs fitnesslogs)
    {
        return toAjax(fitnesslogsService.insertFitnesslogs(fitnesslogs));
    }

    /**
     * 修改健身日志
     */
    @PreAuthorize("@ss.hasPermi('system:fitnesslogs:edit')")
    @Log(title = "健身日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Fitnesslogs fitnesslogs)
    {
        return toAjax(fitnesslogsService.updateFitnesslogs(fitnesslogs));
    }

    /**
     * 删除健身日志
     */
    @PreAuthorize("@ss.hasPermi('system:fitnesslogs:remove')")
    @Log(title = "健身日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(fitnesslogsService.deleteFitnesslogsByLogIds(logIds));
    }
}
